package com.eques.demo.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.eques.bean.DataBean
import com.eques.demo.R
import com.eques.demo.adapter.viewhoder.MsgDetailHoder
import com.eques.impl.OnClickListenerImpl

class MsgAdapter(var context: Context,var parentPos:Int, var beans: List<DataBean> = listOf()) :
    RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    private var onItemClickListener: OnClickListenerImpl? = null

    fun setOnItemClickListener(onItemClickListener: OnClickListenerImpl?) {
        this.onItemClickListener = onItemClickListener
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        var view = LayoutInflater.from(context)
            .inflate(R.layout.item_animal_alarm_details_layout, parent, false)
        return MsgDetailHoder(view)
    }

    override fun getItemCount(): Int {
        return beans.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        var alarmDetailHoder: MsgDetailHoder = holder as MsgDetailHoder
        alarmDetailHoder.setData(context, beans, position)
        alarmDetailHoder.itemView.setOnClickListener{
            onItemClickListener?.CallBackItemClickListener(position,parentPos,0)
        }
    }


}